﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class AddCompareData : Form
    {
        public int ProductID { get; set; }

        public AddCompareData()
        {
            InitializeComponent();
            this.pictureBox1.Hide();
        }

        List<ProductID> PhoneID;
        List<ProductID> PadID;
        List<ProductID> WearID;
        private async void button1_Click(object sender, EventArgs e)
        {
            

            this.pictureBox1.Show();
            UBOXEntities1 db = new UBOXEntities1();

            var q = db.production_product.Select(p => new { ProductID = p.product_id, CategoryID = p.category_id });
            PhoneID = (q.Where(p => p.CategoryID == 1).Select(p => new ProductID{ ID = p.ProductID })).ToList();
            PadID = (q.Where(p => p.CategoryID == 2).Select(p => new ProductID { ID = p.ProductID })).ToList();
            WearID = (q.Where(p => p.CategoryID == 3).Select(p => new ProductID { ID = p.ProductID })).ToList();
            this.dataGridView1.DataSource = PhoneID;
            this.dataGridView2.DataSource = PadID;
            this.dataGridView3.DataSource = WearID;

            Random r = new Random();
            // 2
            for (int i = 0; i < PhoneID.Count; i++)
            {
                for (int j = 0; j < PhoneID.Count; j++)
                {
                    int p1 = PhoneID[i].ID;
                    int p2 = PhoneID[j].ID;
                    if (p2 > p1)
                    {
                        var p = db.compare_2_products.Where(x => x.product_1 == p1 && x.product_2 == p2).FirstOrDefault();
                        if (p == null)
                        {
                            var d = new compare_2_products
                            {
                                product_1 = p1,
                                product_2 = p2,
                                count = Convert.ToInt32(r.NextDouble() * 100)
                            };
                            db.compare_2_products.Add(d);
                        }
                    }
                }
            }
            for (int i = 0; i < PadID.Count; i++)
            {
                for (int j = 0; j < PadID.Count; j++)
                {
                    int p1 = PadID[i].ID;
                    int p2 = PadID[j].ID;
                    if (p2 > p1)
                    {
                          var p = db.compare_2_products.Where(x => x.product_1 == p1 && x.product_2 == p2).FirstOrDefault();
                          if (p == null)
                          {
                              var d = new compare_2_products
                              {
                                  product_1 = p1,
                                  product_2 = p2,
                                  count = Convert.ToInt32(r.NextDouble() * 100)
                              };
                              db.compare_2_products.Add(d);
                          }
                    }
                }
            }
            for (int i = 0; i < WearID.Count; i++)
            {
                for (int j = 0; j < WearID.Count; j++)
                {
                    int p1 = WearID[i].ID;
                    int p2 = WearID[j].ID;
                    if (p2 > p1)
                    {
                          var p = db.compare_2_products.Where(x => x.product_1 == p1 && x.product_2 == p2).FirstOrDefault();
                          if (p == null)
                          {
                              var d = new compare_2_products
                              {
                                  product_1 = p1,
                                  product_2 = p2,
                                  count = Convert.ToInt32(r.NextDouble() * 100)
                              };
                              db.compare_2_products.Add(d);
                          }
                    }
                }
            }
            await db.SaveChangesAsync();
            this.pictureBox1.Hide();
        }

        private async void button2_Click(object sender, EventArgs e)
        {
            this.pictureBox1.Show();
            UBOXEntities1 db = new UBOXEntities1();

            var q = db.production_product.Select(p => new { ProductID = p.product_id, CategoryID = p.category_id });
            PhoneID = (q.Where(p => p.CategoryID == 1).Select(p => new ProductID { ID = p.ProductID })).ToList();
            PadID = (q.Where(p => p.CategoryID == 2).Select(p => new ProductID { ID = p.ProductID })).ToList();
            WearID = (q.Where(p => p.CategoryID == 3).Select(p => new ProductID { ID = p.ProductID })).ToList();
            this.dataGridView1.DataSource = PhoneID;
            this.dataGridView2.DataSource = PadID;
            this.dataGridView3.DataSource = WearID;

            Random r = new Random();
            // 2
            for (int i = 0; i < PhoneID.Count; i++)
            {
                for (int j = 0; j < PhoneID.Count; j++)
                {
                    for (int k = 0; k < PhoneID.Count; k++)
                    {


                        int p1 = PhoneID[i].ID;
                        int p2 = PhoneID[j].ID;
                        int p3 = PhoneID[k].ID;
                        if (p3>p2&&p2 > p1)
                        {
                            var p = db.compare_3_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3).FirstOrDefault();
                            if (p == null)
                            {
                                var d = new compare_3_products
                                {
                                    product_1 = p1,
                                    product_2 = p2,
                                    product_3 = p3,
                                    count = Convert.ToInt32(r.NextDouble() * 100)
                                };
                                db.compare_3_products.Add(d);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < PadID.Count; i++)
            {
                for (int j = 0; j < PadID.Count; j++)
                {
                    for (int k = 0; k < PadID.Count; k++)
                    {
                        int p1 = PadID[i].ID;
                        int p2 = PadID[j].ID;
                        int p3 = PadID[k].ID;
                        if (p3>p2 && p2 > p1)
                        {
                            var p = db.compare_3_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3).FirstOrDefault();
                            if (p == null)
                            {
                                var d = new compare_3_products
                                {
                                    product_1 = p1,
                                    product_2 = p2,
                                    product_3 = p3,
                                    count = Convert.ToInt32(r.NextDouble() * 100)
                                };
                                db.compare_3_products.Add(d);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < WearID.Count; i++)
            {
                for (int j = 0; j < WearID.Count; j++)
                {
                    for (int k = 0; k < WearID.Count; k++)
                    {
                        int p1 = WearID[i].ID;
                        int p2 = WearID[j].ID;
                        int p3 = WearID[k].ID;
                        if (p3>p2&&p2 > p1)
                        {
                            var p = db.compare_3_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3==p3).FirstOrDefault();
                            if (p == null)
                            {
                                var d = new compare_3_products
                                {
                                    product_1 = p1,
                                    product_2 = p2,
                                    product_3 = p3,
                                    count = Convert.ToInt32(r.NextDouble() * 100)
                                };
                                db.compare_3_products.Add(d);
                            }
                        }
                    }
                }
            }
            await db.SaveChangesAsync();
            this.pictureBox1.Hide();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.pictureBox1.Show();
            UBOXEntities1 db = new UBOXEntities1();

            var q = db.production_product.Select(p => new { ProductID = p.product_id, CategoryID = p.category_id });
            PhoneID = (q.Where(p => p.CategoryID == 1).Select(p => new ProductID { ID = p.ProductID })).ToList();
            PadID = (q.Where(p => p.CategoryID == 2).Select(p => new ProductID { ID = p.ProductID })).ToList();
            WearID = (q.Where(p => p.CategoryID == 3).Select(p => new ProductID { ID = p.ProductID })).ToList();
            this.dataGridView1.DataSource = PhoneID;
            this.dataGridView2.DataSource = PadID;
            this.dataGridView3.DataSource = WearID;

            Random r = new Random();
            // 2
            for (int i = 0; i < PhoneID.Count; i++)
            {
                for (int j = 0; j < PhoneID.Count; j++)
                {
                    for (int k = 0; k < PhoneID.Count; k++)
                    {
                        for (int m = 0; m < PhoneID.Count; m++)
                        {
                            int p1 = PhoneID[i].ID;
                            int p2 = PhoneID[j].ID;
                            int p3 = PhoneID[k].ID;
                            int p4 = PhoneID[m].ID;
                            if (p4>p3 && p3 > p2 && p2 > p1)
                            {
                                var p = db.compare_4_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4).FirstOrDefault();
                                if (p == null)
                                {
                                    var d = new compare_4_products
                                    {
                                        product_1 = p1,
                                        product_2 = p2,
                                        product_3 = p3,
                                        product_4 = p4,
                                        count = Convert.ToInt32(r.NextDouble() * 100)
                                    };
                                    db.compare_4_products.Add(d);
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < PadID.Count; i++)
            {
                for (int j = 0; j < PadID.Count; j++)
                {
                    for (int k = 0; k < PadID.Count; k++)
                    {
                        for (int m = 0; m < PadID.Count; m++)
                        {
                            int p1 = PadID[i].ID;
                            int p2 = PadID[j].ID;
                            int p3 = PadID[k].ID;
                            int p4 = PadID[m].ID;
                            if (p4>p3&&p3 > p2 && p2 > p1)
                            {
                                var p = db.compare_4_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4).FirstOrDefault();
                                if (p == null)
                                {
                                    var d = new compare_4_products
                                    {
                                        product_1 = p1,
                                        product_2 = p2,
                                        product_3 = p3,
                                        product_4 = p4,
                                        count = Convert.ToInt32(r.NextDouble() * 100)
                                    };
                                    db.compare_4_products.Add(d);
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < WearID.Count; i++)
            {
                for (int j = 0; j < WearID.Count; j++)
                {
                    for (int k = 0; k < WearID.Count; k++)
                    {
                        for (int m = 0; m < WearID.Count; m++)
                        {
                            int p1 = WearID[i].ID;
                            int p2 = WearID[j].ID;
                            int p3 = WearID[k].ID;
                            int p4 = WearID[m].ID;
                            if (p4>p3&&p3 > p2 && p2 > p1)
                            {
                                var p = db.compare_4_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4).FirstOrDefault();
                                if (p == null)
                                {
                                    var d = new compare_4_products
                                    {
                                        product_1 = p1,
                                        product_2 = p2,
                                        product_3 = p3,
                                        product_4 = p4,
                                        count = Convert.ToInt32(r.NextDouble() * 100)
                                    };
                                    db.compare_4_products.Add(d);
                                }
                            }
                        }
                    }
                }
            }
            db.SaveChanges();
            this.pictureBox1.Hide();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.pictureBox1.Show();
            UBOXEntities1 db = new UBOXEntities1();

            var q = db.production_product.Select(p => new { ProductID = p.product_id, CategoryID = p.category_id });
            PhoneID = (q.Where(p => p.CategoryID == 1).Select(p => new ProductID { ID = p.ProductID })).ToList();
            PadID = (q.Where(p => p.CategoryID == 2).Select(p => new ProductID { ID = p.ProductID })).ToList();
            WearID = (q.Where(p => p.CategoryID == 3).Select(p => new ProductID { ID = p.ProductID })).ToList();
            this.dataGridView1.DataSource = PhoneID;
            this.dataGridView2.DataSource = PadID;
            this.dataGridView3.DataSource = WearID;

            Random r = new Random();
            // 2
            for (int i = 0; i < PhoneID.Count; i++)
            {
                for (int j = 0; j < PhoneID.Count; j++)
                {
                    for (int k = 0; k < PhoneID.Count; k++)
                    {
                        for (int m = 0; m < PhoneID.Count; m++)
                        {
                            for (int n = 0; n < PhoneID.Count; n++)
                            {
                                int p1 = PhoneID[i].ID;
                                int p2 = PhoneID[j].ID;
                                int p3 = PhoneID[k].ID;
                                int p4 = PhoneID[m].ID;
                                int p5 = PhoneID[n].ID;
                                if (p5 > p4 && p4 > p3 && p3 > p2 && p2 > p1)
                                {
                                    var p = db.compare_5_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4 && x.product_5 == p5).FirstOrDefault();
                                    if (p == null)
                                    {
                                        var d = new compare_5_products
                                        {
                                            product_1 = p1,
                                            product_2 = p2,
                                            product_3 = p3,
                                            product_4 = p4,
                                            product_5 = p5,
                                            count = Convert.ToInt32(r.NextDouble() * 100)
                                        };
                                        db.compare_5_products.Add(d);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < PadID.Count; i++)
            {
                for (int j = 0; j < PadID.Count; j++)
                {
                    for (int k = 0; k < PadID.Count; k++)
                    {
                        for (int m = 0; m < PadID.Count; m++)
                        {
                            for (int n = 0; n < PadID.Count; n++)
                            {
                                int p1 = PadID[i].ID;
                                int p2 = PadID[j].ID;
                                int p3 = PadID[k].ID;
                                int p4 = PadID[m].ID;
                                int p5 = PadID[n].ID;
                                if (p5 > p4 && p4 > p3 && p3 > p2 && p2 > p1)
                                {
                                    var p = db.compare_5_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4 && x.product_5 == p5).FirstOrDefault();
                                    if (p == null)
                                    {
                                        var d = new compare_5_products
                                        {
                                            product_1 = p1,
                                            product_2 = p2,
                                            product_3 = p3,
                                            product_4 = p4,
                                            product_5 = p5,
                                            count = Convert.ToInt32(r.NextDouble() * 100)
                                        };
                                        db.compare_5_products.Add(d);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < WearID.Count; i++)
            {
                for (int j = 0; j < WearID.Count; j++)
                {
                    for (int k = 0; k < WearID.Count; k++)
                    {
                        for (int m = 0; m < WearID.Count; m++)
                        {
                            for (int n = 0; n < WearID.Count; n++)
                            {
                                int p1 = WearID[i].ID;
                                int p2 = WearID[j].ID;
                                int p3 = WearID[k].ID;
                                int p4 = WearID[m].ID;
                                int p5 = WearID[n].ID;
                                if (p5>p4&&p4 > p3 && p3 > p2 && p2 > p1)
                                {
                                    var p = db.compare_5_products.Where(x => x.product_1 == p1 && x.product_2 == p2 && x.product_3 == p3 && x.product_4 == p4 && x.product_5 == p5).FirstOrDefault();
                                    if (p == null)
                                    {
                                        var d = new compare_5_products
                                        {
                                            product_1 = p1,
                                            product_2 = p2,
                                            product_3 = p3,
                                            product_4 = p4,
                                            product_5 = p5,
                                            count = Convert.ToInt32(r.NextDouble() * 100)
                                        };
                                        db.compare_5_products.Add(d);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            db.SaveChanges();
            this.pictureBox1.Hide();
        }

 
    }
}
